define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'return_cash/index' + location.search,
                    add_url: 'return_cash/add',
                    //edit_url: 'return_cash/edit',
                    //del_url: 'return_cash/del',
                    multi_url: 'return_cash/multi',
                    table: 'return_cash',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        /*{field: 'payment_id', title: __('Payment_id')},*/
                        /*{field: 'user_id', title: __('User_id')},*/
                        {field: 'users.nickname', title: __('Users.nickname')},
                        {field: 'users.truename', title: __('Users.truename')},
                        {field: 'users.mobile', title: __('Users.mobile')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'cash_charge', title: __('Cash_charge')},
                        {field: 'before_money', title: __('Before_money'), operate:'BETWEEN'},
                        {field: 'pay_style', title: __('Pay_style'), searchList: {"1":__('Pay_style 1'),"2":__('Pay_style 2'),"3":__('Pay_style 3')}, formatter: Table.api.formatter.normal},
                        {field: 'is_over', title: __('Is_over'), searchList: {"0":__('Is_over 0'),"1":__('Is_over 1'),"2":__('Is_over 2')}, formatter: Table.api.formatter.normal},

                        /*{field: 'users.id', title: __('Users.id')},
                        {field: 'users.pid', title: __('Users.pid')},
                        {field: 'users.uuid', title: __('Users.uuid')},
                        {field: 'users.wx_openid', title: __('Users.wx_openid')},
                        {field: 'users.password', title: __('Users.password')},
                        {field: 'users.pay_password', title: __('Users.pay_password')},*/

                        /*{field: 'users.headimg', title: __('Users.headimg')},
                        {field: 'users.id_card', title: __('Users.id_card')},
                        {field: 'users.status', title: __('Users.status')},
                        {field: 'users.alipay', title: __('Users.alipay')},
                        {field: 'users.level', title: __('Users.level')},
                        {field: 'users.qrcode', title: __('Users.qrcode')},*/
                        {field: 'users.balance', title: __('Users.balance'), operate:'BETWEEN'},
                        /*{field: 'users.lover', title: __('Users.lover')},*/
                        /*{field: 'users.province', title: __('Users.province')},
                        {field: 'users.city', title: __('Users.city')},
                        {field: 'users.area', title: __('Users.area')},
                        {field: 'users.createtime', title: __('Users.createtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'users.updatetime', title: __('Users.updatetime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'users.first_log', title: __('Users.first_log')},
                        {field: 'users.day_log', title: __('Users.day_log')},
                        {field: 'users.sign', title: __('Users.sign')},
                        {field: 'users.vip_expire_time', title: __('Users.vip_expire_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'payment.id', title: __('Payment.id')},
                        {field: 'payment.user_id', title: __('Payment.user_id')},*/
                        /*{field: 'payment.varchar', title: __('Payment.varchar')},*/
                        /*{field: 'payment.type', title: __('Payment.type')},*/
                        /*{field: 'payment.status', title: __('Payment.status'), formatter: Table.api.formatter.status},*/
                        /*{field: 'payment.createtime', title: __('Payment.createtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'payment.updatetime', title: __('Payment.updatetime'), operate:'RANGE', addclass:'datetimerange'},*/
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: '', table: table, buttons: [
                                {
                                    name: 'pass',
                                    text: '通过',
                                    icon: 'fa fa-flash',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'return_cash/pass',
                                }
                            ],events: Table.api.events.operate, formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                if(row.is_over == 1||row.is_over == 2){
                                    $(table).data("operate-pass", null);
                                }
                                $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        },
                        {field: 'operate', title: '', table: table, buttons: [
                                {
                                    name: 'unpass',
                                    text: '驳回',
                                    icon: 'fa fa-flash',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'return_cash/unpass',
                                }
                            ],events: Table.api.events.operate, formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                if(row.is_over == 1||row.is_over == 2){
                                    $(table).data("operate-unpass", null);
                                }
                                $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        },
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    Form.api.bindevent($("form[role=form]"));
    return Controller;
});